<?php
/*
 *  www.adminn.cn
*/
define('IMG911', true);
$image_result_path = 'images/img911/'; 
//begin function
function check_url_exists($url) {
    $head=@get_headers($url);
    if(is_array($head))     {
        $t=explode(" ",$head[0]);
        if($t[count($t)-1] == "OK") {
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}
function check_url_host($C_weburl) {
    if(!ereg("^http://[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*$", $C_weburl)) {
        return false;
    }
    return true;
}

function dheader($string, $replace = true, $http_response_code = 0) {
    $string = str_replace(array("\r", "\n"), array('', ''), $string);
    if(empty($http_response_code) || PHP_VERSION < '4.3' ) {
        @header($string, $replace);
    } else {
        @header($string, $replace, $http_response_code);
    }
    if(preg_match('/^\s*location:/is', $string)) {
        exit();
    }
}

function file_ext($filename) {
    return strtolower(trim(substr(strrchr($filename, '.'), 1, 10)));
}
//end function

$url = trim(urldecode($_GET['url'])); 
$url_ext = file_ext($url);   
$arr_allow_ext = array('bmp', 'jpg', 'png', 'gif');    
$arr_site_domain = array(
    'www.ninja911.com',
    'ninja911.com',
    'www.zaizheer.com',
    'zaizheer.com',
    '51cdu.com',
);
if($url) {
    $arr_url_param = parse_url($url);       
    $url_host = strtolower($arr_url_param['host']);
    if($url_host) {
        if(!in_array($url_host, $arr_site_domain)) {  
            if(strtolower(trim(substr($url, 0, 4))) == 'http' || strtolower(trim(substr($url, 0, 5))) == 'https') { 
                if(check_url_exists($url)) {    
                    switch($url_ext) {   
                        case 'jpg':
                            header("Content-type: image/pjpeg");
                            break;
                        case 'gif':
                            header("Content-type: image/gif");
                            break;
                        default:
                            header("Content-type: image/png");
                            break;
                    }
                    set_time_limit(0); //ÔÊÐí³¬Ê±
                    echo @file_get_contents($url);
                } else {
                    dheader("Location: ". $image_result_path ."no_pic_exists_fail.gif");
                }
            } else {
                dheader("Location: ". $image_result_path ."no_pic_url_fail.gif");
            }
        } else {
            dheader("Location: ". $image_result_path ."no_pic_domain_fail.gif");
        }
    } else {
        dheader("Location: ". $image_result_path ."no_pic_200x200.gif");
    }
} else {
    dheader("Location: ". $image_result_path ."no_pic_url_empty.gif");
}
?>
